package logic

import (
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"
	"strconv"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLogic {
	return &AddCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加评论
func (l *AddCommentLogic) AddComment(in *homepage.AddCommentRequest) (*homepage.AddCommentResponse, error) {
	comment, err := dao.AddComment(in)
	if err != nil {
		pkg.Error("评论失败", zap.Error(err))
		return nil, err
	}
	return &homepage.AddCommentResponse{
		Code:      200,
		Msg:       "评论成功",
		CommentId: strconv.FormatInt(comment.ID, 10),
	}, nil
}
